package dao

import (
	"gorm.io/gorm"
	"time"
)

type AuthorizationRecordsImf struct {

}

type AuthorizationWeChat struct {
	Phone string
	WeChatCardUrl string
	WeChatNo string
	CustomerId int64
	CustomerName string
	Account string
}

func (AuthorizationRecordsImf *AuthorizationRecordsImf) GetSendingWeChatRecord(tx *gorm.DB)([]*AuthorizationWeChat, error) {
	var awclist []*AuthorizationWeChat

	err := tx.Raw("select c.phone, awci.we_chat_card_url, awci.we_chat_no, c.id, c.name, ar.cover_authorized_account from authorization_records ar inner join adviser a on a.account = ar.cover_authorized_account inner join distribution_records dr on ar.customer_id = dr.customer_id inner join adviser_we_chat_info awci on ar.cover_authorized_account = awci.account inner join customer c on c.id = ar.customer_id where ar.customer_id not in (select customer_id from sending_mode_record) and ar.customer_id not in (select customer_id from sms_record where sending_type = 2) and a.group_leader = false and dr.allocate_time < ?", time.Now().AddDate(0 ,0 ,-3).Format("2006-01-02 15:04:05")).Scan(&awclist).Error
	if err != nil {
		return nil, err
	}

	return awclist, nil
}
